<!DOCTYPE html>
<html lang="en">

<head>
    <title>Example</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        p {
            border: medium double black;
        }
        
        p.newclass {
            background-color: grey;
            color: white;
        }
    </style>
</head>

<body>
    <p id="textblock" class="fruit numbers">
        There are lots of different kinds of fruit - there are over 500 varieties of banana alone. By the time we add the countless
        types of apples, oranges, and other well-known fruit, we are faced with thousands of choices.
    </p>
    <pre id="results"></pre>
    <button id="toggle">Toggle Class</button>
    <script>
        var results = document.getElementById('results');
        document.getElementById('toggle').onclick = toggleClass;
        listClasses();

        function listClasses() {
            var classlist = document.getElementById('textblock').classList;
            results.innerHTML = "Current classes: ";
            for (let i = 0; i < classlist.length; i++) {
                results.innerHTML += classlist[i] + " ";
            }
        }

        function toggleClass() {
            document.getElementById("textblock").classList.toggle('newclass');
            listClasses();
        }
    </script>
</body>

</html>